package org.example.serviceEdu.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.example.ResultCode.R;
import org.example.serviceEdu.entity.EduCourse;
import org.example.serviceEdu.entity.EduTeacher;
import org.example.serviceEdu.service.EduCourseService;
import org.example.serviceEdu.service.EduTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/serviceEdu/teacherfront")
@CrossOrigin
public class TeacherFrontController {
    @Autowired
    private EduTeacherService teacherService;
    @Autowired
    private EduCourseService courseService;

    //老师分页
    @PostMapping("getTeacherFrontList/{page}/{limit}")
    public R getTeacherFrontList(@PathVariable long page,@PathVariable long limit ){
        Page<EduTeacher> pageTeacher=new Page<>(page,limit);
        Map<String,Object> map=teacherService.geTeacherFrontList(pageTeacher);
        return R.ok().data(map);
    }
    //讲师详情
    @GetMapping("getTeacherFrontInfo/{teacherId}")
    public R getTeacherFrontInfo(@PathVariable String teacherId){
        EduTeacher eduTeacher=teacherService.getById(teacherId);
        //id查课程
        QueryWrapper<EduCourse> wrapper=new QueryWrapper<>();
        wrapper.eq("teacher_id",teacherId);
        List<EduCourse> courseList=courseService.list(wrapper);
        return R.ok().data("teacher",eduTeacher).data("courseList",courseList);
    }

}
